﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Pong_Project
{
    class StringHelper
    {
        public static String wrap(SpriteFont font, String text, Int32 width = 400)
        {
            String line = String.Empty;
            String result = String.Empty;

            // Split by spaces
            String[] words = text.Split(' ');

            // Iterate through all words
            foreach (String word in words)
            {
                if (font.MeasureString(line + word).Length() > width)
                {
                    // Append the line
                    result += line + '\n';

                    // Create new line
                    line = String.Empty;
                }

                // Append previously erased space
                line += word + ' ';
            }

            // Return the result and remaining content
            return result + line;
        }
    }
}
